package com.intsig.airflow.web.model;


import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * @author leojie 2021/3/13 1:49 下午
 */

public class DagEntity {
    public static final String EDGES = "edges";
    public static final String NODES = "nodes";
    /**
     * DAG的名称
     */
    private String label;
    /**
     * DAG 中的数据，包括节点和边关系
     */
    private DagValueEntity value;

    static class DagValueEntity {
        private Set<DagEdge> edges;
        private List<DagNode> nodes;

        public Set<DagEdge> getEdges() {
            return edges;
        }

        public void setEdges(List<DagEdge> edges) {
            if(edges!=null && !edges.isEmpty()){
                this.edges = new HashSet<>(edges);
            }
        }

        public List<DagNode> getNodes() {
            return nodes;
        }

        public void setNodes(List<DagNode> nodes) {
            this.nodes = nodes;
        }
    }

    public String getLabel() {
        return label;
    }

    public void setLabel(String label) {
        this.label = label;
    }

    public DagValueEntity getValue() {
        return value;
    }

    public void setValue(DagValueEntity value) {
        this.value = value;
    }

    public void addNodes(List<DagNode> nodes) {
        if (this.value == null) {
            this.value = new DagEntity.DagValueEntity();
        }
        this.value.setNodes(nodes);
    }

    public void addEdges(List<DagEdge> edges) {
        if (this.value == null) {
            this.value = new DagEntity.DagValueEntity();
        }
        this.value.setEdges(edges);
    }

    public List<DagEdge> getDagEdges() {
        if(this.getValue().getEdges()==null || this.getValue().getEdges().isEmpty()){
            return new ArrayList<>();
        }
        return new ArrayList<>(this.getValue().getEdges());
    }

    public List<DagNode> getDagNodes() {
        return this.getValue().getNodes();
    }

}
